//
//  SceneView.m
//  汽车大灯色温蓝牙
//
//  Created by dfwx on 2020/9/5.
//  Copyright © 2020 zhongdaodianzi. All rights reserved.
//

#import "SceneView.h"
#import "SceneCollectionViewCell.h"


@interface SceneView () <UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) NSArray *dataArray;

@end

/*
 
 名      白       黄      亮度           图片default        图片select
 晴天     100%    0       20%
 夜间     100%    0       100%
 多云     90%    10       100%
 小雨     80%    20       100%
 中雨     100%   30       100%
 大雨     100%   40       100%
 小雪     100%   50       100%
 中雪     100%   60       100%
 大雪     100%   70       100%
 雷雨     100%   80       100%
 小雾     100%   90       100%
 大雾     100%   100       100%


 **/

@implementation SceneView

- (void)awakeFromNib {
    
    [super awakeFromNib];
    [self setUpUI];
}

- (void)setUpUI {
    
    self.selectIndex = 100;
    self.selectTopIndex = 100;
    
    self.dataArray = @[@{@"name":WWNSLocalizedString(@"ExplosionFlash", @"爆闪"),@"white":@"100",@"yellow":@"100",@"bright":@"100",@"default":@"scene_001_default",@"select":@"scene_001_click",@"command":@"010000000000"}, @{@"name":WWNSLocalizedString(@"Gradients", @"渐变"),@"white":@"100",@"yellow":@"100",@"bright":@"100",@"default":@"scene_0001_default",@"select":@"scene_0001_click",@"command":@"020000000000"},    @{@"name":WWNSLocalizedString(@"SlowFlash", @"慢闪"),@"white":@"100",@"yellow":@"100",@"bright":@"100",@"default":@"scene_00001_default",@"select":@"scene_00001_click",@"command":@"030000000000"}, @{@"name":WWNSLocalizedString(@"SunnyDay", @"晴天"),@"white":@"100",@"yellow":@"0",@"bright":@"20",@"default":@"scene_01_default",@"select":@"scene_01_click",@"command":@"d00014000000"},    @{@"name":WWNSLocalizedString(@"AtNight", @"夜间"),@"white":@"100",@"yellow":@"0",@"bright":@"100",@"default":@"scene_02_default",@"select":@"scene_02_click",@"command":@"ff0064000000"},    @{@"name":WWNSLocalizedString(@"cloudy", @"多云"),@"white":@"90",@"yellow":@"10",@"bright":@"100",@"default":@"scene_03_default",@"select":@"scene_03_click",@"command":@"e51a64000000"},    @{@"name":WWNSLocalizedString(@"LightRain", @"小雨"),@"white":@"80",@"yellow":@"20",@"bright":@"100",@"default":@"scene_04_default",@"select":@"scene_04_click",@"command":@"cc3364000000"},    @{@"name":WWNSLocalizedString(@"ModerateRain", @"中雨"),@"white":@"70",@"yellow":@"30",@"bright":@"100",@"default":@"scene_05_default",@"select":@"scene_05_click",@"command":@"b24d64000000"},    @{@"name":WWNSLocalizedString(@"HeavyRain", @"大雨"),@"white":@"60",@"yellow":@"50",@"bright":@"100",@"default":@"scene_06_default",@"select":@"scene_06_click",@"command":@"996664000000"},    @{@"name":WWNSLocalizedString(@"LightSnow", @"小雪"),@"white":@"50",@"yellow":@"50",@"bright":@"100",@"default":@"scene_07_default",@"select":@"scene_07_click",@"command":@"7f7f64000000"},    @{@"name":WWNSLocalizedString(@"ModerateSnow", @"中雪"),@"white":@"40",@"yellow":@"60",@"bright":@"100",@"default":@"scene_08_default",@"select":@"scene_08_click",@"command":@"669964000000"},    @{@"name":WWNSLocalizedString(@"HeavySnow", @"大雪"),@"white":@"30",@"yellow":@"70",@"bright":@"100",@"default":@"scene_09_default",@"select":@"scene_09_click",@"command":@"4db264000000"},    @{@"name":WWNSLocalizedString(@"Thunderstorm", @"雷雨"),@"white":@"20",@"yellow":@"80",@"bright":@"100",@"default":@"scene_10_default",@"select":@"scene_10_click",@"command":@"33cc64000000"},    @{@"name":WWNSLocalizedString(@"Mist", @"小雾"),@"white":@"10",@"yellow":@"90",@"bright":@"100",@"default":@"scene_11_default",@"select":@"scene_11_click",@"command":@"1ae564000000"},    @{@"name":WWNSLocalizedString(@"DenseFog", @"大雾"),@"white":@"0",@"yellow":@"100",@"bright":@"100",@"default":@"scene_12_default",@"select":@"scene_12_click",@"command":@"00ff64000000"}
    ];
    
//    self.nameArray = @[@"爆闪",@"渐变",@"慢闪",@"晴天",@"夜间",@"多云",@"小雨",@"中雨",@"大雨",@"小雪",@"中雪",@"大雪",@"雷雨",@"小雾",@"大雾"];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([SceneCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([SceneCollectionViewCell class])];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    SceneCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SceneCollectionViewCell" forIndexPath:indexPath];

    NSDictionary *dic = self.dataArray[indexPath.row];
    if (indexPath.row < 3) {
        if (indexPath.row == self.selectTopIndex) {
            cell.iconImageView.image = [UIImage imageNamed:dic[@"select"]];

        }else {
            cell.iconImageView.image = [UIImage imageNamed:dic[@"default"]];

        }
    }else {
        if (indexPath.row == self.selectIndex) {
            cell.iconImageView.image = [UIImage imageNamed:dic[@"select"]];

        }else {
            cell.iconImageView.image = [UIImage imageNamed:dic[@"default"]];

        }
    }
    
    cell.nameLabel.text = dic[@"name"];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dic = self.dataArray[indexPath.row];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(SceneViewSelectDic:withIndex:)]) {
        [self.delegate SceneViewSelectDic:dic withIndex:indexPath.row];
    }
    
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        
    return CGSizeMake(collectionView.bounds.size.width/3.0, collectionView.bounds.size.width/3.0 *0.9);
    
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
    

}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {

    return 20;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    
    return 0;
}

- (void)setSelectIndex:(NSInteger)selectIndex {
    
    _selectIndex = selectIndex;
    [self.collectionView reloadData];
}

- (void)setSelectTopIndex:(NSInteger)selectTopIndex {
    
    _selectTopIndex = selectTopIndex;
    [self.collectionView reloadData];
}

@end
